import Util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Demo03_Insert {
    public static void main(String[] args) {
        Connection connection=null;
        PreparedStatement statement=null;
        //ResultSet resultSet=null;不需要，insert返回的是受影响的行数

        try {
            connection=DBUtil.getConnection();
            String sql="insert into student(sn,sname,mail) values(?,?,?)";
            statement=connection.prepareStatement(sql);
            System.out.println("请输入学生学号，姓名，邮箱");
            Scanner scanner=new Scanner(System.in);
            String sn=scanner.next();
            String sname=scanner.next();
            String mail=scanner.next();

            statement.setString(1,sn);
            statement.setString(2,sname);
            statement.setString(2,mail);

            int row=statement.executeUpdate(sql);
            if(row==1){
                System.out.println("输入成功");
            }else {
                System.out.println("输入失败");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            DBUtil.close(null,statement,connection);
        }
    }
}
